{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 单轮对话"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"text\": \"材料：鸡蛋2个，西红柿1个。\\n\\n做法：\\n\\n1. 鸡蛋打入碗中搅拌均匀备用；\\n\\n2. 西红柿洗净切块备用；\\n\\n3. 热锅凉油，油热后放入搅拌好的鸡蛋液，用筷子快速划散成小块，凝固即可盛出备用；\\n\\n4. 锅内再加少量底油，放入西红柿翻炒出汁，倒入炒好的鸡蛋，加入适量盐、糖调味翻匀即可。\", \"finish_reason\": \"stop\", \"choices\": null}\n",
      "{\"input_tokens\": 6, \"output_tokens\": 106, \"total_tokens\": 112}\n"
     ]
    }
   ],
   "source": [
    "# For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html\n",
    "from http import HTTPStatus\n",
    "import dashscope\n",
    "dashscope.api_key = \"sk-9d8f1914800e497f8717144e860f99bc\"\n",
    "\n",
    "\n",
    "def call_with_prompt():\n",
    "    response = dashscope.Generation.call(\n",
    "        model=dashscope.Generation.Models.qwen_turbo,\n",
    "        prompt='如何做炒西红柿鸡蛋？'\n",
    "    )\n",
    "    # The response status_code is HTTPStatus.OK indicate success,\n",
    "    # otherwise indicate request is failed, you can get error code\n",
    "    # and message from code and message.\n",
    "    if response.status_code == HTTPStatus.OK:\n",
    "        print(response.output)  # The output text\n",
    "        print(response.usage)  # The usage information\n",
    "    else:\n",
    "        print(response.code)  # The error code.\n",
    "        print(response.message)  # The error message.\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    call_with_prompt()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 返回结果示例\n",
    "```\n",
    "{\n",
    "    \"status_code\": 200,\n",
    "    \"request_id\": \"e3472c22-274a-9551-b197-f6510608fe1b\",\n",
    "    \"code\": \"\",\n",
    "    \"message\": \"\",\n",
    "    \"output\": {\n",
    "        \"text\": \"材料：\\n西红柿2个，鸡蛋3个，葱花适量，盐适量，糖适量，食用油适量\\n\\n做法：\\n1. 西红柿洗净切块，鸡蛋打入碗中搅拌均匀备用。\\n2. 热锅凉油，油热后加入葱花爆香。\\n3. 加入西红柿块翻炒，炒至西红柿出汁。\\n4. 加入适量的盐和糖，继续翻炒均匀。\\n5. 倒入鸡蛋液，用铲子快速翻炒均匀，使鸡蛋液均匀地裹在西红柿上。\\n6. 炒至鸡蛋熟透即可出锅。\\n\\n提示：\\n1. 炒西红柿时可以适当加一些水，可以使西红柿更加鲜美。\\n2. 炒鸡蛋时要快速翻炒，使鸡蛋均匀地裹在西红柿上，避免炒糊。\\n3. 可以根据个人口味调整盐和糖的用量。\",\n",
    "        \"finish_reason\": \"stop\",\n",
    "        \"choices\": null\n",
    "    },\n",
    "    \"usage\": {\n",
    "        \"input_tokens\": 6,\n",
    "        \"output_tokens\": 193,\n",
    "        \"total_tokens\": 199\n",
    "    }\n",
    "}\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "eec67444d00d22f71b39bd6bbad710a72749a23d029a63a184fb88e8d46e38e1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
